package com.hmdp.config;

import lombok.extern.slf4j.Slf4j;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 计算机系 ITAEM 摆渡人
 * @description
 * @date 2022/11/16 19:55
 */
@Configuration
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String host;
    @Value("${spring.redis.port}")
    private String port;
    @Value("${spring.redis.password}")
    private String password;

    @Bean
    public RedissonClient redissonClient(){
        String address = "redis://" + host + ":" + port;

        //配置类
        Config config = new Config();
        //添加redis地址，此为单点地址。config.useClusterServers()为集群地址
        config.useSingleServer().setAddress(address);
        config.useSingleServer().setPassword(password);
        //创建客户端
        return Redisson.create(config);
    }
}
